<?php

/**
 * User E-Mail validator
 *
 */
class Application_Form_RegisterEmailValidator extends Zend_Validate_Abstract
{

    protected $_messageTemplates = array(
        'emailExists' => "User with E-Mail '%value%' is already exists"
    );
    
    /**
     * Validate interface isValid function
     *
     * @param string $value
     * @return bool
     */
    public function isValid($value)
    {
        if (empty($value)) return false;
        
        $this->_setValue($value);
        
        $userDb=new Application_Model_UserDb();
        
        $user=$userDb->fetchUserByEmail($value);
        
        if ($user->isRegistered())
        {
            $this->_error('emailExists');
            return false;
        }
        
        return true;
    }
}